package model

// User 用户表
type Sleaves struct {
	Id         int    `json:"id" form:"id"`
	Sname      string `json:"sname" form:"sname"`
	Apartment  string `json:"apartment" form:"apartment"`
	Major      string `json:"major" form:"major"`
	Tel        string `json:"tel" form:"tel"`
	Grade      string `json:"grade" form:"grade"`
	Class      string `json:"class" form:"class"`
	Reason     string `json:"reason" form:"reason"`
	Commitment string `json:"Commitment" form:"Commitment"`
	Opinion    string `json:"Opinion" form:"Opinion"`
	Cid        int    `json:"cid" form:"cid"`
}

func SleavesAll(cid string) ([]Sleaves, error) {
	mods := make([]Sleaves, 0, 4)
	err := DB.Select(&mods, "select * from sleave where cid=?", cid)
	return mods, err
}

func Sleaveadd(sname, a, m, tel, g, c, content string, cid int) bool {

	result, _ := DB.Exec("INSERT INTO `sleave` (`sname`,`apartment`,`major`,`tel`,`grade`,`class`,`reason`,`cid` ) VALUES(?,?,?,?,?,?,?,?)", sname, a, m, tel, g, c, content, cid)

	affect, _ := result.RowsAffected()
	if affect == 1 {
		return true
	}
	return false

}
